package DTaskLinkApp::Controller::Link;
use Mojo::Base 'Mojolicious::Controller';
use 5.018;
use warnings;

use Mango;
my $mango = Mango->new;
use Mojo::JSON qw(true false);
use DTask::Utils qw(renderJsonResponse);

use DTask::Link;

sub linkWith
{
	my $c = $_[0];
	my $target_a = $c->stash('target_a');
	my $a_id = $c->stash('a_id');
	my $target_b = $c->stash('target_b');
	my $b_id = $c->stash('b_id');
	DTask::Link::setMango($mango);
	DTask::Link::linkWith($target_a, $a_id, $target_b, $b_id, sub {
		renderJsonResponse($c, @_);	
	});
}

sub unlinkWith
{
	my $c = $_[0];
	my $target_a = $c->stash('target_a');
	my $a_id = $c->stash('a_id');
	my $target_b = $c->stash('target_b');
	my $b_id = $c->stash('b_id');
	DTask::Link::setMango($mango);
	DTask::Link::unlinkWith($target_a, $a_id, $target_b, $b_id, sub {
		renderJsonResponse($c, @_);	
	});
}

sub getAll
{
	my $c = $_[0];
	my $target = $c->stash('target');
	my $id = $c->stash('id');
	DTask::Link::setMango($mango);
	DTask::Link::getAllLinks($target, $id, sub {
		renderJsonResponse($c, @_);	
	});
		
}

1;
